package com.zzh.myapplication.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import net.icarplus.car.R;
import net.icarplus.car.bean.RoapTripBean;

import java.util.List;

/**
 * Created by Administrator on 2016/3/16.
 * 类描述：
 * 创建人：zhangzhonghua
 * 创建时间：16/3/16 10:37
 * 修改人：
 * 修改时间：16/3/16 10:37
 * 修改备注：
 */
public class RoadTripAdapter extends BaseAdapter {
    public List<RoapTripBean> list;
    public Context getContext() {
        return context;
    }
    public RoadTripAdapter(Context context) {
        this.context = context;
    }
    public Context context;
    public RoadTripAdapter(List<RoapTripBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHodle hodle;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_trip, null);
            hodle = new ViewHodle(convertView);
            convertView.setTag(hodle);
        } else {
            hodle = (ViewHodle) convertView.getTag();
        }
            RoapTripBean bean = list.get(position);
            hodle.price.setText(bean.getPrice());
            hodle.addrass.setText(bean.getAddrass());

            hodle.print.setText(bean.getPrint());
            hodle.time.setText(bean.getTime());
            hodle.image.setImageURI(Uri.parse(bean.getCarUrl()));

        return convertView;
    }

    class ViewHodle {
        TextView print, addrass, time, price;
        SimpleDraweeView image;

        public ViewHodle(View view) {
            price = (TextView) view.findViewById(R.id.price);
            addrass = (TextView) view.findViewById(R.id.addrass);
            time = (TextView) view.findViewById(R.id.time);
            print = (TextView) view.findViewById(R.id.print);
            image = (SimpleDraweeView) view.findViewById(R.id.image);
            System.out.print("111dhasd");
        }
    }
}
